package org.robert.export_client.demo;

import com.alibaba.fastjson.JSONObject;
import org.robert.export_client.excel.ExcelWrite;
import org.robert.export_client.excel.entity.WorkbookPathWrite;
import org.robert.export_client.excel.entity.WriteSheet;

import javax.servlet.http.HttpServletResponse;
import java.util.*;

/**
 * @Description
 * @Author robert
 * @Date 2024/1/20 21:15
 **/
public class ExcelLambdaTest {

    public static void main(String[] args) throws Exception {
        HttpServletResponse response = null;
        Map<String, Map<String, String>> dictMap = new HashMap<String, Map<String, String>>();
        HashMap<String, String> map = new HashMap<>();
        map.put("1", "使用");
        map.put("2", "禁用");
        dictMap.put("STATE", map);
        List<ExcelTempDemo> list = new ArrayList<>();
        for(int i=0; i<1000; i++){
            JSONTest jsonTest = new JSONTest("1", "测试" + i, "测试2" + i, "测试3" + i);
            if(i%2 == 0){
                list.add(new ExcelTempDemo(i, "test" + i, "test" + i,
                        "这是一个测试" + i, JSONObject.toJSONString(jsonTest), "1", new Date(),
                        "查询", "查询了" + i+ "数据", "连接" + i, "123254356", "电商", "技术部"));
            }else if(i%5 == 0){
                list.add(new ExcelTempDemo(i, "test" + i, "test" + i,
                        "这是一个测试" + i, JSONObject.toJSONString(jsonTest), "1",null,
                        "查询", "查询了" + i+ "数据", "连接" + i, "123254356", "", "商品部"));
            }else{
                list.add(new ExcelTempDemo(i, "test" + i, "test" + i,
                        "这是一个测试" + i, JSONObject.toJSONString(jsonTest), "0", new Date(),
                        "查询", "查询了" + i+ "数据", "连接" + i, null, "电商", "商品部"));
            }
        }
        long start = System.currentTimeMillis();
        // 单个数据导出
        ExcelWrite.write("C:\\Users\\robert\\Desktop\\").createSheet("Sheet1", ExcelTempDemo.class, dictMap).doWrite(list);

        // 循环导出到多个sheet
//        WorkbookPathWrite build = ExcelWrite.write("D:\\文档\\测试\\").build();
//        for (int j = 0; j < 5; j++){
//            WriteSheet sheet = build.createSheet("Sheet"+j, ExcelTempDemo.class, dictMap).build();
//            List<ExcelTempDemo> list1 = new ArrayList<>();
//            for(int i=j*10000; i< (j+1) * 10000; i++){
//                JSONTest jsonTest = new JSONTest("1", "测试" + i, "测试2" + i, "测试3" + i);
//                list1.add(new ExcelTempDemo(i, "test" + i, "test" + i,
//                        "这是一个测试" + i, JSONObject.toJSONString(jsonTest), "1", new Date()));
//            }
//            build.write(list1, sheet);
//            sheet.finish();
//        }

        // 循环导出到一个sheet
//        WorkbookPathWrite build1 = ExcelWrite.write("D:\\文档\\测试\\").build();
//        WriteSheet sheet1 = build1.createSheet("Sheet1", ExcelTempDemo.class, dictMap).build();
//         List<ExcelTempDemo> list1 = new ArrayList<>();
//        for (int j = 0; j < 5; j++){
//             list1.clear(); // 清空而不是每次都新建
//            for(int i=j*10000; i< (j+1) * 10000; i++){
//                JSONTest jsonTest = new JSONTest("1", "测试" + i, "测试2" + i, "测试3" + i);
//                list1.add(new ExcelTempDemo(i, "test" + i, "test" + i,
//                        "这是一个测试" + i, JSONObject.toJSONString(jsonTest), "1", new Date()));
//            }
//            build.write(list1, sheet1);
//        }
//        sheet1.finish();
//
//        //或者
//        WriteSheet sheet2 = ExcelWrite.write("D:\\文档\\测试\\").createSheet("Sheet1", ExcelTempDemo.class, dictMap).build();
//        for (int j = 0; j < 5; j++){
//            List<ExcelTempDemo> list1 = new ArrayList<>();
//            for(int i=j*10000; i< (j+1) * 10000; i++){
//                JSONTest jsonTest = new JSONTest("1", "测试" + i, "测试2" + i, "测试3" + i);
//                list1.add(new ExcelTempDemo(i, "test" + i, "test" + i,
//                        "这是一个测试" + i, JSONObject.toJSONString(jsonTest), "1", new Date()));
//            }
//            build.write(list1, sheet2);
//        }
//        sheet2.finish();


        long end = System.currentTimeMillis() - start;
        System.out.println(end);
    }
}
